package com.designMode.principle;

/**
 * 接口隔离.
 */
public class InterfaceSegeration_02 {

}


interface MyInter {
	void method();

	void method2();

	void method3();
}

class MyOncePrint implements MyInter {
	@Override
	public void method() {
		System.out.println(1);
	}

	@Override
	public void method2() {
		System.out.println(2);
	}

	@Override
	public void method3() {
		System.out.println(3);
	}
}

class MyDoublePrint implements MyInter {
	@Override
	public void method() {
		System.out.println(11);
	}

	@Override
	public void method2() {
		System.out.println(22);
	}

	@Override
	public void method3() {
		System.out.println(33);
	}
}

/**
 * 无论住该类传入哪个接口的实现类,该类只需要实现类的1和2方法,对于下面类来说,上面两个接口实现类中method3都是多余的
 * 因此原接口拆分为3个小接口,再分别用2个实现类(一个实现类a只实现12,一个实现13),现在该类只要传入实现类a就行了
 */
class OncePrint12 {
	public void onePrint1(MyInter myInter) {
		myInter.method();
	}

	public void onePrint2(MyInter myInter) {
		myInter.method2();
	}
}

class DoublePrint13{
	public void onePrint1(MyInter myInter) {
		myInter.method();
	}

	public void onePrint3(MyInter myInter) {
		myInter.method3();
	}
}

